//
//  AgreementViewController.m
//  CarUser
//
//  Created by 王森林 on 2019/2/2.
//  Copyright © 2019年 王森林. All rights reserved.
//

#import "AgreementViewController.h"

@interface AgreementViewController ()
@property  (nonatomic, strong) NSDictionary *dict;
@end

@implementation AgreementViewController


- (BOOL )fd_prefersNavigationBarHidden{
    return YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"用户协议";
    self.view.backgroundColor = Common_BackgroundColor;
    [self fetchNetWithData];
    // Do any additional setup after loading the view.
}

- (void)fetchNetWithData
{
    
    NSDictionary *params = @{
                             @"FKEY":[CommonMethod createMD5Key:@"PZLXDM"],
                             @"PZLXDM":@"4"
                             };
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [SVProgressHUD showWithStatus:nil];
    });
    
    [[ZY_AfnNetManager shareInstance]postWithURL:Car_API_31 params:params md5Paraname:@"" success:^(id  _Nullable response) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
        
        self.dict = [NSDictionary dictionaryWithDictionary: [response objectForKey:@"info"]];
        [self createUI];
        //        [subscriber sendCompleted];
        
    } fail:^(NSError * _Nonnull error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD showErrorWithStatus:error.localizedDescription];
        });
        //        [subscriber sendCompleted];
    }];
}

- (void)handleBackAction
{
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)createUI
{
    
    
    UIView *navBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, BOUNDWIDTH, NAV_HEIGHT)];
    navBar.backgroundColor = Common_NavigroundColor;
    [self.view addSubview:navBar];
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(15, NAV_HEIGHT-37 , 30, 30);
    [backBtn setImage:IMG(@"nav_back") forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(handleBackAction) forControlEvents:UIControlEventTouchUpInside];
    [navBar addSubview:backBtn];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, NAV_HEIGHT-37, BOUNDWIDTH - 100, 30)];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"用户协议";
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.font = [UIFont systemFontOfSize:18];
    [navBar addSubview:titleLabel];
    
    
    
    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(15, NAV_HEIGHT, BOUNDWIDTH-30, BOUNDHEIGHT - 70- NAV_HEIGHT)];
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[[self.dict objectForKey:@"PZNR00"] dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    textView.attributedText = attributedString;
    [self.view addSubview:textView];
    
    UIView *downView = [[UIView alloc] initWithFrame:CGRectMake(0, BOUNDHEIGHT-70, BOUNDWIDTH, 70)];
    downView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:downView];
    
    UIButton *agressBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [agressBtn setBackgroundColor:RGB(254, 218, 60)];
    agressBtn.frame = CGRectMake(15, 12, BOUNDWIDTH - 30, 45);
    agressBtn.layer.cornerRadius = 20;
    agressBtn.layer.masksToBounds = YES;
    agressBtn.titleLabel.font = FONT_SIZE(15);
    [agressBtn setTitleColor:Common_TextColor forState:UIControlStateNormal];
    [agressBtn setTitle:@"同意并继续" forState:UIControlStateNormal];
    [agressBtn addTarget:self action:@selector(handleAgreeAction) forControlEvents:UIControlEventTouchUpInside];
    [downView  addSubview:agressBtn];
}

-  (void)handleAgreeAction
{
    
    if (self.resultBlock) {
        [self.navigationController popViewControllerAnimated:YES];
        self.resultBlock(@"");
    }
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
